<?php
/**
 * Created by PhpStorm.
 * User: User
 * Date: 2017/12/21
 * Time: 11:12
 */

namespace Kinfy;

class Event
{

    const ON_ARTICLE_READ = 1;
    const ON_ARTICLE_WRITE = 2;

    protected static $listener = [];

    public static function listen($event, &$data = null)
    {
        if (isset(self::$listener[$event])) {
            foreach (self::$listener[$event] as $callback) {
                if (is_callable($callback)) {
                    if ($data) {
                        $callback($data);
                    } else {
                        $callback();
                    }
                }
            }
        }
    }

    public static function addListener($event, $callback)
    {
        self::$listener[$event][] = $callback;
    }

}